/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AreaDeDesenho;

import CapEvents.EventosTranformacao;
import CapEvents.MouseHandler;
import CustomComponents.JCustomColorChooser;
import CustomComponents.JCustomToggleButton;
import Helpers.EFormas;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

/**
 *
 * @author aluno
 */
public class Frame extends JFrame implements ActionListener {

    public MouseHandler mouse;
    public EventosTranformacao transf;
    public PainelDeDesenho painel;
    public JLabel labelXval, labelYval;

    public Frame() {
        //Construtor da superclasse
        super();
        setTitle("Paint.Java");

        //Define layout da tela
        BorderLayout layout = new BorderLayout(2, 2);
        setLayout(layout);

        //Configura painel de Desenho
        this.painel = new PainelDeDesenho();
        this.transf = new EventosTranformacao(this.painel);
        this.mouse = new MouseHandler(this.painel);
        this.painel.addMouseListener(this.mouse);
        this.painel.addMouseMotionListener(this.mouse);
        this.add(painel, BorderLayout.CENTER);

        //Configura Menu
        JPanel painelMenu = new JPanel();
        painelMenu.setSize(new Dimension(this.getSize().width, 60));
        painelMenu.setBackground(Color.DARK_GRAY);
        JMenuBar menuPrincipal = new JMenuBar();
        JMenu menuArquivo = new JMenu("Arquivo");
        JMenu menuTransFormacao = new JMenu("Transformações");


        menuTransFormacao.add(new JMenuItem("Girar")).addActionListener(transf);
        menuTransFormacao.add(new JMenuItem("Escalar")).addActionListener(transf);
        menuTransFormacao.add(new JMenuItem("Transladar")).addActionListener(transf);
        menuTransFormacao.add(new JMenuItem("Deformar")).addActionListener(transf);
        menuTransFormacao.add(new JSeparator(SwingConstants.HORIZONTAL));
        menuTransFormacao.add(new JMenuItem("Desfazer")).addActionListener(transf);
        menuTransFormacao.add(new JMenuItem("Refazer")).addActionListener(transf);
        menuTransFormacao.addMenuListener(transf);

        menuArquivo.add(new JMenuItem("Salvar")).addActionListener(mouse);
        menuArquivo.add(new JMenuItem("Abrir")).addActionListener(mouse);
        menuArquivo.add(new JMenuItem("Limpar Tela")).addActionListener(mouse);
        menuArquivo.add(new JSeparator(SwingConstants.HORIZONTAL));
        menuArquivo.add(new JMenuItem("Sair")).addActionListener(this);
        menuPrincipal.add(menuArquivo);
        menuPrincipal.add(menuTransFormacao);
        painelMenu.setLayout(new BorderLayout());
        painelMenu.add(menuPrincipal, BorderLayout.CENTER);
        this.add(painelMenu, BorderLayout.NORTH);

        //Criar painel de funcoes
        JPanel painelLateral = new JPanel();
        painelLateral.setLayout(new GridLayout(20, 2, 2, 2));
        painelLateral.setSize(100, this.getHeight());

        //Cria barra de status
        JPanel statusBar = new JPanel();
        statusBar.setSize(this.getSize().width, 50);
        statusBar.setLayout(new GridLayout(1, 20));
        JLabel labelX = new JLabel("Posicao do Mouse X :");
        JLabel labelY = new JLabel("Posicao do Mouse Y :");
        labelXval = new JLabel("");
        labelYval = new JLabel("");
        statusBar.add(labelX);
        statusBar.add(labelXval);
        statusBar.add(new JSeparator(SwingConstants.VERTICAL));
        statusBar.add(labelY);
        statusBar.add(labelYval);
        this.add(statusBar, BorderLayout.SOUTH);

        JCustomToggleButton line = new JCustomToggleButton(EFormas.LINE);
        JCustomToggleButton quadrado = new JCustomToggleButton(EFormas.RETANGULO);
        JCustomToggleButton circulo = new JCustomToggleButton(EFormas.CIRCULO);
        JCustomToggleButton quadradoPreenchido = new JCustomToggleButton(EFormas.FILL_RETANGULO);
        JCustomToggleButton circuloPreenchido = new JCustomToggleButton(EFormas.FILL_CIRCULO);
        JCustomToggleButton retanguloArrendodado = new JCustomToggleButton(EFormas.RETANGULO_ARRENDONDADO);
        JCustomToggleButton retanguloArrendondadoFill = new JCustomToggleButton(EFormas.FILL_RETANGULO_ARRENDONDADO);
        JCustomToggleButton triangulo = new JCustomToggleButton(EFormas.TRIANGULO);
        JCustomToggleButton fillTriangulo = new JCustomToggleButton(EFormas.FILL_TRIANGULO);
        JCustomToggleButton Selecionar = new JCustomToggleButton(EFormas.NONE);
        Selecionar.setSelected(true);

        quadrado.setSize(new Dimension(20, 20));
        quadrado.setText("");
        painelLateral.add(line);
        painelLateral.add(quadrado);
        painelLateral.add(circulo);
        painelLateral.add(quadradoPreenchido);
        painelLateral.add(circuloPreenchido);
        painelLateral.add(retanguloArrendodado);
        painelLateral.add(retanguloArrendondadoFill);
        painelLateral.add(triangulo);
        painelLateral.add(fillTriangulo);
        painelLateral.add(Selecionar);
        this.add(painelLateral, BorderLayout.WEST);


        JCustomColorChooser choser = new JCustomColorChooser(painel);
        this.add(choser, BorderLayout.EAST);


        //Ajusta dimensoes e exibe a tela
        setSize(new Dimension(800, 600));
        setVisible(true);
        setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setExtendedState(MAXIMIZED_BOTH);

    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        addMouseListener(mouse);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        this.setVisible(false);
    }
}
